# Import numpy
import numpy as np
import pandas as pd
# Import basic object from the Qiskit
from qiskit import QuantumCircuit
from qiskit import Aer,BasicAer
from qiskit import execute
# We will need these two
from qiskit.utils import QuantumInstance
from qiskit_machine_learning.kernels import QuantumKernel
# Load account from the disk
from qiskit import IBMQ
IBMQ.load_account()
# We will need this for plots
from qiskit.visualization import plot_histogram,plot_bloch_multivector
ibmqfactory.load_account:WARNING:2022-03-13 17:57:22,860: Credentials are already in use. The existing account in the session will be replaced.
# Check the version of the qiskit you use
# Compared to previous class, I have installed the up-to-date version
import qiskit.tools.jupyter
%qiskit_version_table
%qiskit_copyright
| Qiskit Software | Version |
|---|---|
qiskit-terra | 0.19.2 |
qiskit-aer | 0.10.3 |
qiskit-ignis | 0.7.0 |
qiskit-ibmq-provider | 0.18.3 |
qiskit | 0.34.2 |
qiskit-machine-learning | 0.3.1 |
| System information | |
| Python version | 3.8.12 |
| Python compiler | Clang 10.0.0 |
| Python build | default, Oct 12 2021 06:23:56 |
| OS | Darwin |
| CPUs | 4 |
| Memory (Gb) | 8.0 |
| Sun Mar 13 17:50:17 2022 GMT | |
© Copyright IBM 2017, 2022.
This code is licensed under the Apache License, Version 2.0. You may
obtain a copy of this license in the LICENSE.txt file in the root directory
of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
Any modifications or derivative works of this code must retain this
copyright notice, and modified files need to carry a notice indicating
that they have been altered from the originals.
# Ideal simulator
simulator = Aer.get_backend('qasm_simulator')
# Real-like simulator
from qiskit.providers.aer.noise import NoiseModel
# Choose a particuler quantum computer
provider = IBMQ.load_account()
backend = provider.get_backend('ibmq_belem')
# We derive the noise model from the chosen quantum computer
noise_model = NoiseModel.from_backend(backend)
# Further, we assume the specific qauntum computer:
# Get coupling map from backend
coupling_map = backend.configuration().coupling_map
# Get basis gates from noise model
basis_gates = noise_model.basis_gates
# define backend (simulator with specific noise)
backendSimWithNoise = QuantumInstance(
Aer.get_backend("qasm_simulator"),
coupling_map=coupling_map,
basis_gates=basis_gates,
noise_model=noise_model,
shots=1024
)
ibmqfactory.load_account:WARNING:2022-03-13 17:51:24,385: Credentials are already in use. The existing account in the session will be replaced.
from sklearn import datasets
data = datasets.load_breast_cancer()
This is a good classification dataset in the sklearn library.
# dataframe
df = pd.DataFrame(data.data, columns=data.feature_names)
df['target'] = data.target
import seaborn as sns
%matplotlib inline
sns.pairplot(df)
<seaborn.axisgrid.PairGrid at 0x7f9138ad8040>